import multiprocessing
import time
import os


def worker(task_id):
    """
    子进程要执行的任务
    """
    print(f"进程 {task_id} (PID: {os.getpid()}) 开始执行")
    time.sleep(2)
    print(f"进程 {task_id} 执行完毕")


if __name__ == "__main__":
    processes = []

    for i in range(3):

        p = multiprocessing.Process(target=worker, args=(i,))
        processes.append(p)
        p.start()
    
    for p in processes:
        p.join()

    print("所有进程执行完毕！")